package com.hello.booksale.filter;

import com.hello.booksale.util.JwtUtil;
import com.hello.booksale.util.RecaptchaUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class RecaptchaFilter extends OncePerRequestFilter {

    private static final Logger logger = LoggerFactory.getLogger(RecaptchaFilter.class);
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        if(request.getRequestURI().equals("/login")&&request.getMethod().equalsIgnoreCase("post")){
//            String gRecaptchaResponse = request.getParameter("g-recaptcha-response");
//            Boolean isOK=RecaptchaUtil.verify(gRecaptchaResponse);
//            if(!isOK)
//            {
//                throw new AuthenticationServiceException("验证失败!");
//            }
//           response.setContentType("text/html;charset=utf-8");
//           response.getWriter().write("验证码验证失败");
//           return;

        }
        filterChain.doFilter(request, response);
    }

}
